<?php
/**
 * 前端视频的管理
 *
 * Author: lyun
 * Date: 2018/1/27
 * Created by Panxsoft.
 */
namespace App\Http\Controllers\Home;

use App\Http\Models\Video;
use App\Http\Models\VideoType;
use App\Http\Requests\Home\VideoIndexRequest;
use App\Services\Utils\ApiChecker;
use App\Services\Utils\ApiResponser;
use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class VideoController extends Controller
{
    use ApiResponser,ApiChecker;

    /**
     * @param VideoIndexRequest $request
     * @return array|\Illuminate\Http\Response
     */
    public function index(VideoIndexRequest $request)
    {
        $video_types = VideoType::pluck('name', 'id')->all();

        $video_type_ids = array_keys($video_types);
        $videos = Video::FilterVideoTypeId($request->video_type_id)
            ->whereIn('video_type_id', $video_type_ids)
            ->latest('sort')
            ->paginate($request->per_page?:15);

        return $this->response(compact('videos'));
    }

    /**
     * @return array|\Illuminate\Http\Response
     */
    public function create()
    {
        $video_types = VideoType::pluck('name', 'id')->all();

        return $this->response(compact('video_types'));
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function returnView()
    {
        return view("official_website.video");
    }
}
